<?php
/**
 * Created by PhpStorm.
 * User: yjh
 * Date: 17/5/12
 * Time: 上午11:32
 */
include ('db.php');

function getCatePath($cid,&$result = array()){

    $sql = "select * from deepcate WHERE id = $cid";

    //面向对象编程
    global $mysqli;
    $re = $mysqli->query($sql);
    //从结果集中取出一条数据为 关联数组
    $row = mysqli_fetch_assoc($re);
    if ($row){
        $result[] = $row;
        getCatePath($row['pid'],$result);

    }

    //ksort() 函数用于对数组单元按照键名从低到高进行排序。
    //krsort() 函数用于对数组单元按照键名从高到低进行排序。
    krsort($result);
    return $result;

    //面向过程编程
//    $re = mysqli_query($mysqli,$sql);
//    print_r($re);die;
//    $row = mysqli_fetch_assoc($re);
//    print_r($row);die;

}
    function displayCatePath($cid,$url = "cate.php?cid="){
        $res =  getCatePath($cid);
        $str = '';
        print_r($res);
        foreach ($res as $k=>$v){
            $str.= "<a href='{$url}{$v['id']}'>{$v['catename']}</a>>";
        }
        return $str;
    }
    echo displayCatePath(10,'cate.php?page=1&id=');
